﻿#region License statement
// NJamb, a specification and delta-specification DSL
// Copyright (c) 2010-2011, Mark Knell
// Published under the MIT License; all other rights reserved
#endregion

#region using...
using NJamb.Specifications;
using Stile.Patterns.SelfDescribingPredicates;
using Stile.Patterns.SelfDescribingPredicates.Evaluators;
#endregion

namespace NJamb.Parser.SpecificationBuilders.SubjectHas
{
    public abstract class FluentHas<TSubject, TSpecifies> : IFluentHas<TSubject, TSpecifies>,
        ICollaboratingHas<TSubject, TSpecifies>
        where TSpecifies : class, ISpecification
    {
        private readonly ICollaboratingSpecificationBuilder<TSubject, TSpecifies> _specificationBuilder;

        protected FluentHas(ICollaboratingSpecificationBuilder<TSubject, TSpecifies> specificationBuilder)
        {
            _specificationBuilder = specificationBuilder;
        }

        public ICollaboratingSpecificationBuilder<TSubject, TSpecifies> SpecificationBuilder
        {
            get { return _specificationBuilder; }
        }
        public ICollaboratingHas<TSubject, TSpecifies> Xray
        {
            get { return this; }
        }

        public TSpecifies HashCode(int hashCode)
        {
            Evaluator<TSubject, int> evaluator = Expect<TSubject>.HashCode(hashCode);
            TSpecifies specifies = _specificationBuilder.Specify(evaluator);
            return specifies;
        }
    }
}
